﻿namespace td.Core.Xml
{
    using System;
    using System.Xml;

    public class AutoStartXml : IXmlStorage
    {
        private string @class;
        private string desc;
        private string id;
        private string name;

        public AutoStartXml()
        {
            this.id = "";
            this.@class = "";
            this.name = "";
            this.desc = "";
        }

        public AutoStartXml(string id, string classname, string name)
        {
            this.id = id;
            this.@class = classname;
            this.name = name;
            this.desc = "";
        }

        public override bool Equals(object o)
        {
            if (o is AutoStartXml)
            {
                AutoStartXml xml = (AutoStartXml)o;
                return (string.Equals(this.@class, xml.@class) && string.Equals(this.name, xml.name));
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public void GetValueFromXml(XmlNode objectNode)
        {
            if ((objectNode != null) && objectNode.Name.ToLower().Equals("autostart"))
            {
                XmlAttributeCollection attributes = objectNode.Attributes;
                for (int i = 0; i < attributes.Count; i++)
                {
                    XmlAttribute attribute = attributes[i];
                    if (attribute.Name.ToLower().Equals("id"))
                    {
                        this.id = attribute.Value;
                    }
                    if (attribute.Name.ToLower().Equals("name"))
                    {
                        this.name = attribute.Value;
                    }
                    if (attribute.Name.ToLower().Equals("class"))
                    {
                        this.@class = attribute.Value;
                    }
                    if (attribute.Name.ToLower().Equals("desc"))
                    {
                        this.desc = attribute.Value;
                    }
                }
            }
        }

        public void SetValueToXml(XmlDocument xmldoc, XmlElement parentEle)
        {
            XmlElement newChild = xmldoc.CreateElement("AutoStart");
            newChild.SetAttribute("id", this.id);
            newChild.SetAttribute("name", this.name);
            newChild.SetAttribute("class", this.@class);
            newChild.SetAttribute("desc", this.desc);
            parentEle.AppendChild(newChild);
        }

        public override string ToString()
        {
            return ("[AutoStartXml" + this.name + "]");
        }

        public string Class
        {
            get
            {
                return this.@class;
            }
            set
            {
                this.@class = value;
            }
        }

        public string Description
        {
            get
            {
                return this.desc;
            }
            set
            {
                this.desc = value;
            }
        }

        public string ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }
    }
}

